package com.company.test27_28;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Administrator on 2016.11.9.
 */
public class Test2708 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String fileName=input.next();
        File file=new File(fileName);
        try{
            input=new Scanner(file);
        }catch (FileNotFoundException e){
            System.out.println("文件不存在");
            return;
        }

        int n=Integer.valueOf(input.nextLine());
        List<AbstractGraph.Edge> edges=new ArrayList<>();
        for(int i=0;i<n;i++){
            String line=input.nextLine();
            Scanner deal=new Scanner(line);

            int u=deal.nextInt();
            while (deal.hasNext()){
                edges.add(new AbstractGraph.Edge(u,deal.nextInt()));
            }
        }

        Graph<Integer> graph=new UnweightedGraph<Integer>(edges,n);
        List<Integer> list=graph.getHamiltonianPath(0);
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
}
